import { createRouter, createWebHistory } from 'vue-router'
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';// 导入样式，否则看不到效果
import Home from '@/views/Home.vue'
import Login from '@/views/Login.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
    	path: '/',
    	name: 'root',
    	redirect:"/login",
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/home',
      name: 'home',
      component: () => import('@/views/Home.vue')
    },
  ]
})
router.beforeEach((to, from, next) => {
	NProgress.start() // 显示进度条
	//console.log("from=>" + JSON.stringify(from));
	//console.log("to  =>" + JSON.stringify(to));
	if (to.name) {

	}
	next();
})

router.afterEach((to, from, failure) => {
	NProgress.done() // 完成进度条
})

router.onError(error => {
	console.error(error);
})
export default router
